<script setup lang="ts">
import { baseURL } from '@/utils/http'
import { ref, onMounted } from 'vue'
import { useMemberStore } from '@/stores'
import type { userItem } from '@/types/member'
import { postLoginWxMinAPI } from '@/api/account'

const memberStore = useMemberStore()

const form = ref<userItem>()

// 获取个人信息
const getMemberProfileData = async () => {
  // 获取微信code
  const rescode = await wx.login()
  const { code } = rescode

  // 发起请求
  const loginrRes = await postLoginWxMinAPI(code)

  // const res = await getUserInfoByIdAPI(memberStore.profile.userId)
  memberStore.setProfile(loginrRes.data.appUser)
  form.value = memberStore.profile
}

onMounted(() => {
  getMemberProfileData()
})

const onSubmit = () => {
  uni.navigateTo({ url: '/pages/attes/attesEdit' })
  // if (form.value?.nameStatus == 1) {
  //   uni.navigateTo({ url: '/pages/attes/attesEdit' })
  // } else {
  //   uni.showToast({ icon: 'none', title: '已经实名认证过的用户，暂时不支持修改实名认证信息！'})
  // }
}
</script>
<template>
  <!-- 表单 -->
  <view class="form">
    <!-- 表单内容 -->
    <view class="form-content">
      <view class="form-item">
        <text class="label">姓名</text>
        <text class="info">{{ form?.name }}</text>
      </view>
      <view class="form-item">
        <text class="label">昵称</text>
        <text class="info">{{ form?.nickname }}</text>
      </view>
      <view class="form-item">
        <text class="label">身份证号</text>
        <text class="info">{{ form?.idCard }}</text>
      </view>
      <view class="form-item image_upload">
        <text class="label">身份证正面</text>
        <view class="upload" v-if="form?.frontCardImage">
          <image :src="form?.frontCardImage" mode="aspectFill" />
        </view>
        <text class="no_info" v-else> 暂无证件图片 </text>
      </view>
      <view class="form-item image_upload">
        <text class="label">身份证背面</text>
        <view class="upload" v-if="form?.backCardImage">
          <image :src="form?.backCardImage" mode="aspectFill" />
        </view>
        <text class="no_info" v-else> 暂无证件图片 </text>
      </view>
      <view class="form-item">
        <text class="label">电话号码</text>
        <text class="info">{{ form?.phone }}</text>
      </view>
      <view class="form-item">
        <text class="label">认证状态</text>
        <view class="info"
          ><uni-tag
            :text="form?.nameStatus == 1 ? '待认证' : '已认证'"
            size="small"
            :type="form?.nameStatus == 1 ? 'default' : 'success'"
        /></view>
      </view>
    </view>
    <!-- 提交按钮 -->
    <button class="form-button" @tap="onSubmit">修改信息</button>
  </view>
</template>

<style lang="scss" scoped>
</style>
